package db

import (
	"blockchains-aio/util"
	"time"
)

const (
	INSERT_SLOGAN   = `insert into t_slogan (name, local_path, url,createtime) values(?,?,?,?)`
	SELECT_SLOGAN10 = `select * from t_slogan order by createtime desc limit 10`
)

func CreateSlogan(name, local_path, url string) error {
	createtime := time.Now()

	_, _, err := dbPlus.Exec(INSERT_SLOGAN, name, local_path, url, &createtime)

	return err
}

func GetSlogan() *Slogan {
	slogan, err := dbPlus.QueryOne(SELECT_SLOGAN10)

	if err != nil || slogan == nil {
		return nil
	}
	id, _ := util.GetInt(util.GetMapValue2(slogan, "id", "0"))

	rtn := &Slogan{
		Id:         int(id),
		Name:       util.GetMapValue2(slogan, "name", ""),
		LocalPath:  util.GetMapValue2(slogan, "local_path", ""),
		Url:        util.GetMapValue2(slogan, "url", ""),
		Createtime: nil,
	}
	//2022-05-13 13:54:40.5049073+08:00

	return rtn
}
